package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * TODO
 *
 * @Author mr.wu
 * @Data #{DATE} #{TIME}
 */
@RestController
@RequestMapping("/admin/shop")
@Slf4j
public class ShopController {
    @Autowired
    private ShopService shopService;
    @Autowired
    private StringRedisTemplate redisTemplate;

    private static final String KEY = "SHOP_STATUS";
    /**
     * 修改店铺的营业状态
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    public Result updateaStatus(@PathVariable Integer status) {
        log.info("设置店铺的营业状态为：{}",status == 1 ? "营业中" : "打烊中");
        redisTemplate.opsForValue().set(KEY, String.valueOf(status));
        return Result.success();
    }

    /**
     * 管理端查询回显店铺状态
     * @return
     */
    @GetMapping("/status")
    public Result getStatus(){

        String s = redisTemplate.opsForValue().get(KEY);
        Integer status = Integer.valueOf(s);
        log.info("获取店铺的营业状态为：{}",status == 1 ? "营业中" : "打烊中");
        return Result.success(status);
    }
}
